package com.pn.taikao.controller;

import com.pn.taikao.dto.ApiResponse;
import com.pn.taikao.dto.CreateResponse;
import com.pn.taikao.dto.PageResult;
import com.pn.taikao.dto.PaperQueryRequest;
import com.pn.taikao.dto.ManualPaperRequest;
import com.pn.taikao.dto.AutoPaperRequest;
import com.pn.taikao.dto.TypeRule;
import com.pn.taikao.entity.Course;
import com.pn.taikao.entity.Paper;
import com.pn.taikao.entity.PaperQuestion;
import com.pn.taikao.entity.Question;
import com.pn.taikao.entity.User;
import com.pn.taikao.entity.PaperStudent;
import com.pn.taikao.service.CourseService;
import com.pn.taikao.service.PaperService;
import com.pn.taikao.service.PaperQuestionService;
import com.pn.taikao.service.PaperStudentService;
import com.pn.taikao.service.QuestionService;
import com.pn.taikao.service.StudentCourseService;
import com.pn.taikao.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/papers")
public class PaperController {

    private final PaperService paperService;
    private final PaperQuestionService paperQuestionService;
    private final CourseService courseService;
    private final QuestionService questionService;
    private final PaperStudentService paperStudentService;
    private final StudentCourseService studentCourseService;

    public PaperController(PaperService paperService, 
                          PaperQuestionService paperQuestionService,
                          CourseService courseService,
                          QuestionService questionService,
                          PaperStudentService paperStudentService,
                          StudentCourseService studentCourseService) {
        this.paperService = paperService;
        this.paperQuestionService = paperQuestionService;
        this.courseService = courseService;
        this.questionService = questionService;
        this.paperStudentService = paperStudentService;
        this.studentCourseService = studentCourseService;
    }

    /**
     * 手动组卷（教师权限）
     */
    @PostMapping("/manual")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<CreateResponse> createManualPaper(@RequestBody ManualPaperRequest request) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        // 验证课程
        Course course = courseService.getById(request.getPaper().getCourseId());
        if (course == null) {
            return ApiResponse.error("课程不存在");
        }
        
        // 教师只能为自己的课程创建试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!course.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限为该课程创建试卷");
            }
        }
        
        // 验证题目数量
        if (request.getQuestionIds() == null || request.getQuestionIds().isEmpty()) {
            return ApiResponse.error("至少需要选择一道题目");
        }
        
        // 验证题目是否存在且属于该课程
        for (Long questionId : request.getQuestionIds()) {
            Question question = questionService.getById(questionId);
            if (question == null) {
                return ApiResponse.error("题目不存在：ID=" + questionId);
            }
            if (!question.getCourseId().equals(request.getPaper().getCourseId())) {
                return ApiResponse.error("题目不属于该课程：ID=" + questionId);
            }
        }
        
        // 创建试卷
        Paper paper = new Paper();
        paper.setName(request.getPaper().getName());
        paper.setTeacherId(currentUserId);
        paper.setCourseId(request.getPaper().getCourseId());
        paper.setDuration(request.getPaper().getDuration());
        // 开始时间和结束时间可选，在考试管理中设置
        if (request.getPaper().getStartTime() != null && !request.getPaper().getStartTime().isEmpty()) {
            paper.setStartTime(LocalDateTime.parse(request.getPaper().getStartTime(), DateTimeFormatter.ISO_DATE_TIME));
        }
        if (request.getPaper().getEndTime() != null && !request.getPaper().getEndTime().isEmpty()) {
            paper.setEndTime(LocalDateTime.parse(request.getPaper().getEndTime(), DateTimeFormatter.ISO_DATE_TIME));
        }
        paper.setStatus("draft"); // 默认状态为草稿
        paper.setCreateBy(SecurityUtils.getCurrentUsername());
        
        Long paperId = paperService.createPaper(paper);
        
        // 添加题目到试卷
        List<Double> scores = request.getScores();
        for (int i = 0; i < request.getQuestionIds().size(); i++) {
            Long questionId = request.getQuestionIds().get(i);
            Double score = (scores != null && i < scores.size()) ? scores.get(i) : 5.0;
            paperQuestionService.addQuestionToPaper(paperId, questionId, score);
        }
        
        return ApiResponse.success(new CreateResponse(paperId));
    }

    /**
     * 自动组卷（教师权限）
     */
    @PostMapping("/auto")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<CreateResponse> createAutoPaper(@RequestBody AutoPaperRequest request) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        // 验证课程
        Course course = courseService.getById(request.getPaper().getCourseId());
        if (course == null) {
            return ApiResponse.error("课程不存在");
        }
        
        // 教师只能为自己的课程创建试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!course.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限为该课程创建试卷");
            }
        }
        
        // 创建试卷
        Paper paper = new Paper();
        paper.setName(request.getPaper().getName());
        paper.setTeacherId(currentUserId);
        paper.setCourseId(request.getPaper().getCourseId());
        paper.setDuration(request.getPaper().getDuration());
        // 开始时间和结束时间可选，在考试管理中设置
        if (request.getPaper().getStartTime() != null && !request.getPaper().getStartTime().isEmpty()) {
            paper.setStartTime(LocalDateTime.parse(request.getPaper().getStartTime(), DateTimeFormatter.ISO_DATE_TIME));
        }
        if (request.getPaper().getEndTime() != null && !request.getPaper().getEndTime().isEmpty()) {
            paper.setEndTime(LocalDateTime.parse(request.getPaper().getEndTime(), DateTimeFormatter.ISO_DATE_TIME));
        }
        paper.setStatus("draft"); // 默认状态为草稿
        paper.setCreateBy(SecurityUtils.getCurrentUsername());
        
        Long paperId = paperService.createPaper(paper);
        
        // 自动组卷逻辑
        List<Long> selectedQuestionIds = new ArrayList<>();
        List<Double> selectedScores = new ArrayList<>();
        
        Map<String, TypeRule> typeRules = request.getRule().getTypeRules();
        Map<String, Integer> difficultyDistribution = request.getRule().getDifficultyDistribution();
        
        // 按题型和难度抽取题目
        Random random = new Random();
        for (Map.Entry<String, TypeRule> entry : typeRules.entrySet()) {
            String type = entry.getKey();
            TypeRule rule = entry.getValue();
            int count = rule.getCount();
            Double score = rule.getScore();
            
            // 获取该课程该题型的所有题目
            List<Question> allQuestions = questionService.list(type, request.getPaper().getCourseId(), null, null, 1, 1000);
            
            if (allQuestions.isEmpty()) {
                continue;
            }
            
            // 按难度筛选题目
            List<Question> filteredQuestions = new ArrayList<>();
            if (difficultyDistribution != null && !difficultyDistribution.isEmpty()) {
                // 根据难度分布抽取题目
                int easyCount = (int) (count * difficultyDistribution.getOrDefault("easy", 0) / 100.0);
                int mediumCount = (int) (count * difficultyDistribution.getOrDefault("medium", 0) / 100.0);
                int hardCount = count - easyCount - mediumCount;
                
                List<Question> easyQuestions = allQuestions.stream()
                    .filter(q -> "easy".equals(q.getDifficulty()))
                    .collect(Collectors.toList());
                List<Question> mediumQuestions = allQuestions.stream()
                    .filter(q -> "medium".equals(q.getDifficulty()))
                    .collect(Collectors.toList());
                List<Question> hardQuestions = allQuestions.stream()
                    .filter(q -> "hard".equals(q.getDifficulty()))
                    .collect(Collectors.toList());
                
                // 随机抽取
                filteredQuestions.addAll(randomSelect(easyQuestions, Math.min(easyCount, easyQuestions.size())));
                filteredQuestions.addAll(randomSelect(mediumQuestions, Math.min(mediumCount, mediumQuestions.size())));
                filteredQuestions.addAll(randomSelect(hardQuestions, Math.min(hardCount, hardQuestions.size())));
                
                // 如果数量不足，从剩余题目中补充
                while (filteredQuestions.size() < count && filteredQuestions.size() < allQuestions.size()) {
                    Question q = allQuestions.get(random.nextInt(allQuestions.size()));
                    if (!filteredQuestions.contains(q)) {
                        filteredQuestions.add(q);
                    }
                }
            } else {
                // 没有难度分布要求，随机抽取
                filteredQuestions = randomSelect(allQuestions, Math.min(count, allQuestions.size()));
            }
            
            // 添加到试卷
            for (Question question : filteredQuestions) {
                selectedQuestionIds.add(question.getId());
                selectedScores.add(score);
            }
        }
        
        if (selectedQuestionIds.isEmpty()) {
            paperService.deletePaper(paperId);
            return ApiResponse.error("没有找到符合条件的题目，请检查题库或调整组卷规则");
        }
        
        // 添加题目到试卷
        for (int i = 0; i < selectedQuestionIds.size(); i++) {
            paperQuestionService.addQuestionToPaper(paperId, selectedQuestionIds.get(i), selectedScores.get(i));
        }
        
        return ApiResponse.success(new CreateResponse(paperId));
    }

    /**
     * 随机选择题目
     */
    private List<Question> randomSelect(List<Question> questions, int count) {
        if (questions.size() <= count) {
            return new ArrayList<>(questions);
        }
        
        List<Question> selected = new ArrayList<>();
        Random random = new Random();
        List<Question> temp = new ArrayList<>(questions);
        
        for (int i = 0; i < count && !temp.isEmpty(); i++) {
            int index = random.nextInt(temp.size());
            selected.add(temp.remove(index));
        }
        
        return selected;
    }

    /**
     * 更新试卷（教师权限，只能更新自己创建的试卷）
     */
    @PutMapping("/{id}")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> update(@PathVariable("id") Long id, @RequestBody Paper paper) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        // 检查试卷是否存在
        Paper existPaper = paperService.getById(id);
        if (existPaper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 管理员可以修改任何试卷，教师只能修改自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!existPaper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限修改该试卷");
            }
        }
        
        paper.setId(id);
        paper.setUpdateBy(SecurityUtils.getCurrentUsername());
        paperService.updatePaper(paper);
        return ApiResponse.success(null);
    }

    /**
     * 删除试卷（教师权限，只能删除自己创建的试卷）
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> delete(@PathVariable("id") Long id) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        // 检查试卷是否存在
        Paper existPaper = paperService.getById(id);
        if (existPaper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 管理员可以删除任何试卷，教师只能删除自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!existPaper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限删除该试卷");
            }
        }
        
        // 先删除试卷题目关联
        paperQuestionService.clearPaperQuestions(id);
        // 再删除试卷
        paperService.deletePaper(id);
        return ApiResponse.success(null);
    }

    /**
     * 查询试卷详情（包含题目列表）
     */
    @GetMapping("/{id}")
    @PreAuthorize("hasAnyRole('ADMIN','TEACHER','STUDENT')")
    public ApiResponse<PaperDetailResponse> detail(@PathVariable("id") Long id) {
        Paper paper = paperService.getById(id);
        if (paper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 获取试卷题目
        List<PaperQuestion> paperQuestions = paperQuestionService.getByPaperId(id);
        List<QuestionDetail> questionDetails = new ArrayList<>();
        
        for (PaperQuestion pq : paperQuestions) {
            Question question = questionService.getById(pq.getQuestionId());
            if (question != null) {
                QuestionDetail qd = new QuestionDetail();
                qd.setId(question.getId());
                qd.setType(question.getType());
                qd.setContent(question.getContent());
                qd.setOptions(question.getOptions());
                qd.setAnswer(question.getAnswer());
                qd.setAnalysis(question.getAnalysis());
                qd.setDifficulty(question.getDifficulty());
                qd.setScore(pq.getScore()); // 使用试卷中的分值
                questionDetails.add(qd);
            }
        }
        
        PaperDetailResponse response = new PaperDetailResponse();
        response.setPaper(paper);
        response.setQuestions(questionDetails);
        
        return ApiResponse.success(response);
    }

    /**
     * 获取当前教师的所有试卷
     */
    @GetMapping("/my")
    @PreAuthorize("hasRole('TEACHER')")
    public ApiResponse<List<Paper>> getMyPapers() {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        List<Paper> papers = paperService.getByTeacherId(currentUserId);
        return ApiResponse.success(papers);
    }

    /**
     * 根据课程ID获取试卷列表（不分页，用于下拉选择）
     */
    @GetMapping("/course/{courseId}")
    @PreAuthorize("hasAnyRole('ADMIN','TEACHER','STUDENT')")
    public ApiResponse<List<Paper>> getByCourse(@PathVariable("courseId") Long courseId) {
        List<Paper> papers = paperService.getByCourseId(courseId);
        return ApiResponse.success(papers);
    }

    /**
     * 分页查询试卷列表
     */
    @PostMapping("/query")
    @PreAuthorize("hasAnyRole('ADMIN','TEACHER','STUDENT')")
    public ApiResponse<PageResult<Paper>> list(@RequestBody PaperQueryRequest request) {
        // 处理默认值
        int page = (request.getPage() != null && request.getPage() > 0) ? request.getPage() : 1;
        int size = (request.getSize() != null && request.getSize() > 0) ? request.getSize() : 10;
        
        // 如果不是管理员，教师只能查看自己的试卷
        Long teacherId = request.getTeacherId();
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (currentUser.getRoleType().equalsIgnoreCase("TEACHER")) {
                // 教师只能查看自己的试卷
                teacherId = SecurityUtils.getCurrentUserId();
            }
        }
        
        List<Paper> data = paperService.list(request.getName(), teacherId, request.getCourseId(), page, size);
        long total = paperService.count(request.getName(), teacherId, request.getCourseId());
        PageResult<Paper> pageResult = new PageResult<>(data, total, page, size);
        return ApiResponse.success(pageResult);
    }

    /**
     * 更新试卷题目（手动组卷后修改题目）
     */
    @PutMapping("/{id}/questions")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> updatePaperQuestions(@PathVariable("id") Long id, 
                                                  @RequestBody UpdatePaperQuestionsRequest request) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        // 检查试卷是否存在
        Paper existPaper = paperService.getById(id);
        if (existPaper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 管理员可以修改任何试卷，教师只能修改自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!existPaper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限修改该试卷");
            }
        }
        
        // 更新试卷题目
        paperQuestionService.setPaperQuestions(id, request.getQuestionIds(), request.getScores());
        return ApiResponse.success(null);
    }

    /**
     * 发布试卷（支持指定学生或全部发布）
     */
    @PutMapping("/{id}/publish")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> publish(@PathVariable("id") Long id, @RequestBody(required = false) Map<String, Object> request) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        Paper paper = paperService.getById(id);
        if (paper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 验证权限：教师只能发布自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!paper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限发布该试卷");
            }
        }
        
        // 发布试卷
        paperService.publishPaper(id);
        
        // 处理学生发布关系
        List<Long> studentIds = null;
        if (request != null && request.containsKey("studentIds")) {
            Object studentIdsObj = request.get("studentIds");
            if (studentIdsObj instanceof List) {
                studentIds = ((List<?>) studentIdsObj).stream()
                    .map(obj -> {
                        if (obj instanceof Number) {
                            return ((Number) obj).longValue();
                        }
                        return Long.parseLong(obj.toString());
                    })
                    .collect(Collectors.toList());
            }
        }
        
        // 如果指定了学生ID列表，则只发布给这些学生；否则发布给该课程的所有学生
        if (studentIds != null && !studentIds.isEmpty()) {
            // 先删除该试卷的所有发布关系
            paperStudentService.deleteByPaperId(id);
            
            // 创建新的发布关系
            List<PaperStudent> paperStudents = new ArrayList<>();
            String username = SecurityUtils.getCurrentUsername();
            for (Long studentId : studentIds) {
                PaperStudent paperStudent = new PaperStudent();
                paperStudent.setPaperId(id);
                paperStudent.setStudentId(studentId);
                paperStudent.setCreateBy(username);
                paperStudents.add(paperStudent);
            }
            if (!paperStudents.isEmpty()) {
                paperStudentService.addPaperStudents(paperStudents);
            }
        } else {
            // 发布给该课程的所有学生
            List<com.pn.taikao.entity.User> students = studentCourseService.getStudentsByCourseId(paper.getCourseId());
            if (!students.isEmpty()) {
                // 先删除该试卷的所有发布关系
                paperStudentService.deleteByPaperId(id);
                
                // 创建新的发布关系
                List<PaperStudent> paperStudents = new ArrayList<>();
                String username = SecurityUtils.getCurrentUsername();
                for (com.pn.taikao.entity.User student : students) {
                    PaperStudent paperStudent = new PaperStudent();
                    paperStudent.setPaperId(id);
                    paperStudent.setStudentId(student.getId());
                    paperStudent.setCreateBy(username);
                    paperStudents.add(paperStudent);
                }
                paperStudentService.addPaperStudents(paperStudents);
            }
        }
        
        return ApiResponse.success(null);
    }

    /**
     * 取消发布试卷
     */
    @PutMapping("/{id}/unpublish")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> unpublish(@PathVariable("id") Long id) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }
        
        Paper paper = paperService.getById(id);
        if (paper == null) {
            return ApiResponse.error("试卷不存在");
        }
        
        // 验证权限：教师只能取消发布自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!paper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限取消发布该试卷");
            }
        }
        
        // 取消发布试卷
        paperService.unpublishPaper(id);
        
        // 删除所有发布关系
        paperStudentService.deleteByPaperId(id);
        
        return ApiResponse.success(null);
    }

    /**
     * 更新试卷的考试时间
     */
    @PutMapping("/{id}/exam-time")
    @PreAuthorize("hasRole('TEACHER') or hasRole('ADMIN')")
    public ApiResponse<Void> updateExamTime(@PathVariable("id") Long id, @RequestBody Map<String, String> request) {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        if (currentUserId == null) {
            return ApiResponse.error("未登录");
        }

        Paper paper = paperService.getById(id);
        if (paper == null) {
            return ApiResponse.error("试卷不存在");
        }

        // 验证权限：教师只能更新自己创建的试卷
        User currentUser = SecurityUtils.getCurrentUser();
        if (currentUser != null && !currentUser.getRoleType().equalsIgnoreCase("ADMIN")) {
            if (!paper.getTeacherId().equals(currentUserId)) {
                return ApiResponse.error("无权限更新该试卷");
            }
        }

        String startTimeStr = request.get("startTime");
        String endTimeStr = request.get("endTime");

        if (startTimeStr != null && !startTimeStr.isEmpty()) {
            paper.setStartTime(LocalDateTime.parse(startTimeStr, DateTimeFormatter.ISO_DATE_TIME));
        }
        if (endTimeStr != null && !endTimeStr.isEmpty()) {
            paper.setEndTime(LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_DATE_TIME));
        }

        paper.setUpdateBy(SecurityUtils.getCurrentUsername());
        paperService.updatePaper(paper);
        return ApiResponse.success(null);
    }

    /**
     * 试卷详情响应DTO
     */
    private static class PaperDetailResponse {
        private Paper paper;
        private List<QuestionDetail> questions;

        public Paper getPaper() { return paper; }
        public void setPaper(Paper paper) { this.paper = paper; }
        public List<QuestionDetail> getQuestions() { return questions; }
        public void setQuestions(List<QuestionDetail> questions) { this.questions = questions; }
    }

    /**
     * 题目详情DTO
     */
    private static class QuestionDetail {
        private Long id;
        private String type;
        private String content;
        private Map<String, String> options;
        private String answer;
        private String analysis;
        private String difficulty;
        private Double score;

        // Getters and Setters
        public Long getId() { return id; }
        public void setId(Long id) { this.id = id; }
        public String getType() { return type; }
        public void setType(String type) { this.type = type; }
        public String getContent() { return content; }
        public void setContent(String content) { this.content = content; }
        public Map<String, String> getOptions() { return options; }
        public void setOptions(Map<String, String> options) { this.options = options; }
        public String getAnswer() { return answer; }
        public void setAnswer(String answer) { this.answer = answer; }
        public String getAnalysis() { return analysis; }
        public void setAnalysis(String analysis) { this.analysis = analysis; }
        public String getDifficulty() { return difficulty; }
        public void setDifficulty(String difficulty) { this.difficulty = difficulty; }
        public Double getScore() { return score; }
        public void setScore(Double score) { this.score = score; }
    }

    /**
     * 更新试卷题目请求DTO
     */
    private static class UpdatePaperQuestionsRequest {
        private List<Long> questionIds;
        private List<Double> scores;

        public List<Long> getQuestionIds() { return questionIds; }
        public void setQuestionIds(List<Long> questionIds) { this.questionIds = questionIds; }
        public List<Double> getScores() { return scores; }
        public void setScores(List<Double> scores) { this.scores = scores; }
    }
}

